<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>用户管理</title>
</head>
<body>
	<div class="layui-collapse">
	 <div class="layui-colla-item">
	  <h2 class="layui-colla-title">用户信息</h2>
	   <div class="layui-colla-content layui-show">
		<fieldset class="layui-elem-field layui-field-title">
		 <legend>查询条件</legend>
		 <div class="layui-field-box">
		 	<form class="layui-form">
				
				<div class="layui-form-item">
					<label class="layui-form-label">用户帐号</label>
						<div class="layui-input-inline">
							<input class="layui-input" name="code" type="text" placeholder="请输入用户帐号">
					</div>
					<label class="layui-form-label">用户名称</label>
						<div class="layui-input-inline">
							<input class="layui-input" name="name" type="text" placeholder="请输入用户名称">
					</div>
					<div class="layui-input-inline">
						<input type="button" value="查询" class="layui-btn" lay-submit lay-filter="sel" />
						<input type="reset" value="重置" class="layui-btn layui-btn-primary" />		
					</div>
					<div class="layui-input-inline">
						<input type="button" value="添加" class="layui-btn" onclick='openAdd()' />
					</div>
				</div>	
				<input type="hidden" name='pageIndex' value='1' />	
				<input type="hidden" name='pageLimit' value='10' />	
			</form>
		   </div>
		  </fieldset>
		 </div>	 
		</div>
	</div>
	<table class="layui-table">
		<colgroup>
			<col width="15%"><col width="25%">
			<col width="25%"><col>
		</colgroup>
		<thead>
			<th>序号</th><th>帐号</th><th>名称</th><th>操作</th>
		</thead>
		<tbody id="user_tbody"></tbody>
	</table>
	
	<div id='pageInfo' style="text-align:right; padding-right:30px" ></div>
	
	<script type="text/javascript">
		element.render();
		
		function openAdd(){
			openLayer("/web/sys/user/add.jsp",refresh)
		}
		
		formOn('submit(sel)','/user/selectModel.do','json',function(data){
			var pageIndex = $("input[name='pageIndex']").val();
			var pageLimit = $("input[name='pageLimit']").val();
			
			setPageInfo('pageInfo',data.count,pageIndex,pageLimit,function(obj,first){
				$("input[name='pageIndex']").val(obj.curr);  // 得到当前页，以便向服务端请求对应页的数据。
				$("input[name='pageLimit']").val(obj.limit); // 得到每页显示的条数
				if(!first){refresh()}	// 首次不执行
			})	
			
			var html=''
			$.each(data.data,function(index,element){
				element.id = (index+1)+(pageIndex-1)*pageLimit;
				html += getlaytpl("#tradd",element)
			})
			$("#user_tbody").html(html);
		});
		
		
		refresh();
		function refresh(){
			$("input[value='查询']").click();
		}
		
		
		function openUpd(code){
			openLayer("/web/sys/user/update.jsp?code="+code,refresh)
		}
		
		function openUpdPas(code){
			openLayer("/web/sys/user/updPas.jsp?code="+code,refresh)
		}
		
	
		
		function del(code){
			openConfirm(function(index){
				ajax({code:code},'/user/delete.do','text',function(data){
					if(1==data){
						layer.msg("删除成功",refresh)
					}else{
						layer.msg("删除失败")
					}
				})
			},"确定删除该记录？")
		}
		
		
	</script>
	
	<script type="text/html" id ='tradd'>
	<tr>
		<td>{{ d.id }}</td>
		<td>{{ d.code }}</td>
		<td>{{ d.name?d.name : "暂未填写" }}</td>
		<td>
			<input onclick='del("{{d.code}}")' type='button' value='删除' class='layui-btn-sm layui-btn-danger' >
			&nbsp;
			<input onclick='openUpd("{{d.code}}")' type='button' value='修改用户信息' class='layui-btn-sm' >
			&nbsp;
			<input onclick='openUpdPas("{{d.code}}")' type='button' value='修改用户密码' class='layui-btn-sm' >
		</td>	
	</tr>
	</script>

</body>
</html>